//
//  SportsMap_ViewController.m
//  Bicycle
//
//  Created by dllo on 16/4/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SportsMap_ViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface SportsMap_ViewController ()<MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property(nonatomic,strong)CLLocationManager *lM;
@property(nonatomic,assign)BOOL isChange;
@end

@implementation SportsMap_ViewController
+(SportsMap_ViewController *)shareInstance{
    
    static SportsMap_ViewController *mapVC = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        mapVC = [[SportsMap_ViewController alloc]init];
    });
    
    return mapVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //地图类型
    //    self.mapView.mapType = MKMapTypeSatelliteFlyover;
    //缩放
    //    self.mapView.zoomEnabled = NO;
    //比例尺
    //    self.mapView.showsScale = YES;
    //调用方法
    [self lM];
    
    if (self.isStart) {
        [self.lM startUpdatingLocation];
    }else{
        [self.lM stopUpdatingLocation];
    }
    
    //显示用户位置
    //    self.mapView.showsUserLocation = YES;
    self.mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading;

}
-(CLLocationManager *)lM{
    
    if (!_lM) {
        
        _lM = [[CLLocationManager alloc]init];
        if ([_lM respondsToSelector:@selector(requestAlwaysAuthorization)]) {
            
            [_lM requestAlwaysAuthorization];
        }
    }
    return _lM;
}

- (IBAction)backToWatch:(id)sender {
     [self dismissViewControllerAnimated:YES completion:nil];
    
}
- (IBAction)DMap:(UIButton *)sender {
    
    if (!self.isChange) {
        self.mapView.mapType = MKMapTypeSatelliteFlyover;
        [sender setTitle:@"2D" forState:(UIControlStateNormal)];
    }else{
        self.mapView.mapType = MKMapTypeStandard;
        [sender setTitle:@"3D" forState:(UIControlStateNormal)];
    }
    self.isChange = !self.isChange;
    
}
- (IBAction)TrackLocation:(id)sender {
    
    self.mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading;
    
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
    
    MKCoordinateSpan span = MKCoordinateSpanMake(0.005, 0.003);
    MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.location.coordinate, span);
    
    [self.mapView setRegion:region animated:YES];
    [self.mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
